<?php
if($_GET['mode']=="edit"){
   if($_POST['submit_test']!=true) echo '';
   else {
      $select_u = mysql_query('SELECT teacher_to FROM users WHERE username = "'.$_SESSION['username'].'"');
      $row_u = mysql_fetch_assoc($select_u);
	  
	  $test=$_POST['place'];
	  $vupros=htmlspecialchars(trim(addslashes($_POST['q_name'])));
	  $otg1=htmlspecialchars(trim(addslashes($_POST[1])));
	  $otg2=htmlspecialchars(trim(addslashes($_POST[2])));
	  $otg3=htmlspecialchars(trim(addslashes($_POST[3])));
	  $otg4=htmlspecialchars(trim(addslashes($_POST[4])));
	  $real_otg=$_POST['question'];
	  
	  if(empty($vupros)||empty($otg1)||empty($otg2)||empty($otg3)||empty($otg4)||empty($real_otg)){
		 echo '<p class="error">Моля, попълнете ВСИЧКИ полета!</p>';
	  }
	  else{
		 $select_name='SELECT vapros FROM questions WHERE vapros="' . $vupros . '" AND id!='.$_GET['qid'].'';
		 $result_name=mysql_query($select_name);
		 if(mysql_num_rows($result_name)!=0){
			echo '<p class="error">Въпросът съществува!</p>'; 
		 }
		 else{
			$insert_question='UPDATE questions SET testid="'.$test.'", vapros="'.$vupros.'", a="'.$otg1.'", b="'.$otg2.'", c="'.$otg3.'", d="'.$otg4.'", otg="'.$real_otg.'" WHERE id='.$_GET['id'].'';
			$res_question=mysql_query($insert_question);
			echo '<p class="success">Успешен запис!</p>'; 
			echo '<meta http-equiv="refresh" content="0;url=editquestions.php?id=1">';
		 }
	  }
   }
}
?>